﻿#region Copyright Notice
// 
// 
//  
//  Copyright (c) 2009-2011 Anindya Chatterjee
//  
//  Licensed under the Apache License, Version 2.0 (the "License");
//  you may not use this file except in compliance with the License.
//  You may obtain a copy of the License at
//  
//      http://www.apache.org/licenses/LICENSE-2.0
//  
//  Unless required by applicable law or agreed to in writing, software
//  distributed under the License is distributed on an "AS IS" BASIS,
//  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
//  See the License for the specific language governing permissions and
//  limitations under the License.
// 
// 
#endregion
using System;
using System.Collections.Generic;

namespace AbstractClass.NPerf.Framework
{
    /// <summary>
    /// Instructs the NPerf test runner to call the method for testing.
    /// </summary>
    [AttributeUsage(AttributeTargets.Method, AllowMultiple = false)]
    public sealed class PerfTestAttribute : Attribute
    {
        /// <summary>
        /// The number of iterations per thread.
        /// </summary>
        /// <value>The number of test iterations.</value>
        public int TestIterations;

        /// <summary>
        /// The number of concurrent threads on which the test method will run.
        /// </summary>
        /// <value>The number of concurrent threads.</value>
        public int Threads;

        /// <summary>
        /// Initializes a new instance of the <see cref="PerfTestAttribute"/> class.
        /// </summary>
        /// <remarks>The test method will run on one thread and for one iteration only and NPerf will
        /// not collect any performance data for the method. This attribute is only for the methods
        /// containing assert statements.</remarks>
        /// <example>
        /// <code>
        /// 
        /// [PerfTest]
        /// public void TestMethod()
        /// {
        ///     Assert.That(The.HitCountOf(AnotherTestMethod), Is.InBetween(10, 30));
        /// }
        /// 
        /// </code>
        /// </example>
        public PerfTestAttribute()
            : this(TestType.None)
        {
            TestIterations = 1;
            Threads = 1;
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="PerfTestAttribute"/> class.
        /// </summary>
        /// <param name="testTypes">The types of the performance data to collect.</param>
        /// <remarks>The test method will run on two different threads and for two iteration on each thread.</remarks>
        /// <example>
        /// <code>
        /// 
        /// [PerfTest(TestType.HitCount, TestType.Duration)]
        /// public void TestMethod()
        /// {
        ///     Console.WriteLine("Hello World");
        /// }
        /// 
        /// </code> 
        /// </example>
        public PerfTestAttribute(params TestType[] testTypes)
        {
            Threads = 2;
            TestIterations = 2;
            TestTypes = new List<TestType>(testTypes);
        }

        /// <summary>
        /// Gets the types of the performance data to collect.
        /// </summary>
        public List<TestType> TestTypes { get; internal set; }
    }
}